package com.ruoyi.spider.spiderConfig.handle;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.spider.domain.SpiderArticle;
import com.vdurmont.emoji.EmojiParser;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author xgt(小光头)
 * @version 1.0
 * @date 2021-1-17 15:03
 */
public class Defaulthandle implements handle {
    @Override
    public Object process(Object object) {


        JSONObject jsonObject = JSONObject.parseObject(object.toString());
        Map<String,Object> spiderMap = (Map<String,Object>)jsonObject;


        //去除所有表情 标题与内容
        String title = EmojiParser.removeAllEmojis(spiderMap.get("title").toString());
        spiderMap.put("title",title);
        String content = EmojiParser.removeAllEmojis(spiderMap.get("content").toString());
        //处理标题
        StringBuffer stringBufferContent = new StringBuffer("<p></p><p>");
        stringBufferContent.append("</br>");
        stringBufferContent.append(title);
        stringBufferContent.append("</br>");
        stringBufferContent.append(StrUtil.removeAll(content,"\n"));
        stringBufferContent.append("</p>");
        spiderMap.put("content",stringBufferContent.toString());




        return spiderMap;
    }
}
